package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.User;
import dao.imp.UserDaoImp;

/**
 * Servlet implementation class ShowALLServlet
 */
public class ShowALLServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowALLServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		List<User> list = new UserDaoImp().findAll();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter writer=response.getWriter();
		writer.write("所有注册信息");
		writer.write("<table border='1'>");
		writer.write("<tr>");
		writer.write("<td>姓名</td>");
		writer.write("<td>月薪</td>");
		writer.write("<td>生日</td>");
		writer.write("<td>性别</td>");
		writer.write("</tr>");
		for(User user:list){
			String birth = dateFormat.format(user.getBirth());
			writer.write("<tr>");
			writer.write("<td>"+user.getUname()+"</td>");
			writer.write("<td>"+user.getSal()+"</td>");
			writer.write("<td>"+birth+"</td>");
			writer.write("<td>"+user.getSex()+"</td>");
			writer.write("</tr>");
		}
		writer.write("</table>");
		writer.close();
	}

}
